﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HARTCalibrationTool.Observers
{
    public class TransducerCalFlgUpdater : IObserver
    {
        private CheckBox[,] _checkBoxes = null;

        public TransducerCalFlgUpdater(CheckBox[,] checkBoxes) 
        { 
            _checkBoxes = checkBoxes;
        }

        public void Update(List<string> listStr)
        {
            int channel = int.Parse(listStr[0]);
            byte tempCalFlg = byte.Parse(listStr[1]);
            byte pressureCalFlg = byte.Parse(listStr[2]);
            byte currentCalFlg = byte.Parse(listStr[3]);
            byte serUDSetCalFlg = byte.Parse(listStr[4]);

            // Temperature Cal Flg
            if (tempCalFlg == 0x01)
            {
                _checkBoxes[channel, 0].Checked = true;
            }

            // Pressure Cal Flg
            if (pressureCalFlg == 0x01)
            {
                _checkBoxes[channel, 1].Checked = true;
            }

            // Current Cal Flg
            if (currentCalFlg == 0x01)
            {
                _checkBoxes[channel, 2].Checked = true;
            }

            // Sensor Range Cal Flg
            if (serUDSetCalFlg == 0x01)
            {
                _checkBoxes[channel, 3].Checked = true;
            }
        }
    }

    public class TransducerCalFlgTemperaturePointsUpdater : IObserver
    {
        private TextBox[] _textBoxes;
        public TransducerCalFlgTemperaturePointsUpdater(TextBox[] textBoxes)
        {
            _textBoxes = textBoxes;
        }

        public void Update(List<string> listStr)
        {
            int channel = 0;
            int tempPoints = 0;
            
            if (int.TryParse(listStr[0], out channel))
            {
                _textBoxes[channel].Text = listStr[1];

                if (int.TryParse(listStr[1], out tempPoints))
                {
                    if (tempPoints != 6)
                    {
                        _textBoxes[channel].ForeColor = Color.Red;
                    }
                }
            }
        }
    }

    public class BackupFacParamUpdater : IObserver
    {
        private CheckBox[] _checkBoxes;

        public BackupFacParamUpdater(CheckBox[] checkBoxes) 
        { 
            _checkBoxes = checkBoxes;
        }

        public void Update(List<string> listStr)
        {
            int channel = 0;

            if (int.TryParse(listStr[0], out channel))
            {
                _checkBoxes[channel].Checked = true;
            }
        }
    }
}
